*** net/if_sl.c.orig	Thu Apr  7 16:45:26 1988
--- net/if_sl.c	Thu Apr  7 16:48:20 1988
***************
*** 38,64 ****
  #include "sl.h"
  #if NSL > 0
  
! #include "param.h"
! #include "mbuf.h"
! #include "buf.h"
! #include "dk.h"
! #include "socket.h"
! #include "ioctl.h"
! #include "file.h"
! #include "tty.h"
! #include "errno.h"
  
! #include "if.h"
! #include "netisr.h"
! #include "route.h"
  #if INET
  #include "../netinet/in.h"
  #include "../netinet/in_systm.h"
! #include "../netinet/in_var.h"
  #include "../netinet/ip.h"
  #endif
  
  #include "../machine/mtpr.h"
  
  /*
   * N.B.: SLMTU is now a hard limit on input packet size.
--- 38,66 ----
  #include "sl.h"
  #if NSL > 0
  
! #include "../h/param.h"
! #include "../h/mbuf.h"
! #include "../h/buf.h"
! #include "../h/dk.h"
! #include "../h/socket.h"
! #include "../h/ioctl.h"
! #include "../h/file.h"
! #include "../h/tty.h"
! #include "../h/errno.h"
  
! #include "../net/if.h"
! #include "../net/netisr.h"
! #include "../net/route.h"
  #if INET
  #include "../netinet/in.h"
  #include "../netinet/in_systm.h"
! /* #include "../netinet/in_var.h" */
  #include "../netinet/ip.h"
  #endif
  
+ #ifndef sun
  #include "../machine/mtpr.h"
+ #endif
  
  /*
   * N.B.: SLMTU is now a hard limit on input packet size.
***************
*** 85,95 ****
--- 87,142 ----
  #define TRANS_FRAME_END	 	0334		/* transposed frame end */
  #define TRANS_FRAME_ESCAPE 	0335		/* transposed frame esc */
  
+ #ifdef sun
+ #define t_sc t_linep
+ extern	char	mclrefcnt[];
+ #else
  #define t_sc T_LINEP
+ #endif
  
  int sloutput(), slioctl(), ttrstrt();
  
+ #ifndef mtocl
+ /* virtual address to network cluster number */
+ #define	mtocl(x) (((int)x - (int)mbutl) >> CLSHIFT)
+ #endif
+ 
  /*
+  * Mbuf page cluster macros.
+  * MCLALLOC allocates mbuf page clusters.
+  * Note that it works only with a count of 1 at the moment.
+  * MCLGET adds such clusters to a normal mbuf.
+  * m->m_len is set to CLBYTES upon success.
+  * MCLFREE frees clusters allocated by MCLALLOC.
+  */
+ #ifndef MCLALLOC
+ #define	MCLALLOC(m, i) \
+ 	{ int ms = splimp(); \
+ 	  if (mclfree == 0) \
+ 		(void)m_clalloc(1, MPG_CLUSTERS, M_DONTWAIT); \
+ 	  if ((m)=mclfree) \
+ 	     {++mclrefcnt[mtocl(m)];mbstat.m_clfree--;mclfree = (m)->m_next;} \
+ 	  splx(ms); }
+ #endif
+ 
+ #ifndef MCLGET
+ #define	MCLGET(m) \
+ 	{ struct mbuf *p; \
+ 	  MCLALLOC(p, 1); \
+ 	  if (p) { \
+ 		(m)->m_off = (int)p - (int)(m); \
+ 		(m)->m_len = CLBYTES; \
+ 	  } \
+ 	}
+ #endif
+ #ifndef MCLFREE
+ #define	MCLFREE(m) { \
+ 	if (--mclrefcnt[mtocl(m)] == 0) \
+ 	    { (m)->m_next = mclfree;mclfree = (m);mbstat.m_clfree++;} \
+ 	}
+ #endif
+ 
+ /*
   * Called from boot code to establish sl interfaces.
   */
  slattach()
***************
*** 121,126 ****
--- 168,186 ----
  	register struct sl_softc *sc;
  	register int nsl;
  
+ #ifndef BSD4_3
+ 	if (sl_softc->sc_if.if_name == NULL) {
+ 		slattach();		/* XXX */
+ 		if (ifnet != NULL && !bcmp(ifnet->if_name, "lo", sizeof "lo")) {
+ 			register struct ifnet *ifp;
+ 
+ 			ifp = ifnet->if_next;
+ 			ifnet->if_next = NULL;
+ 			ifnet = ifp;
+ 			loattach();	/* XXX */
+ 		}
+ 	}
+ #endif
  	if (!suser())
  		return (EPERM);
  	if (tp->t_line == SLIPDISC)
***************
*** 388,395 ****
--- 448,457 ----
  			m_freem(top);
  			return (NULL);
  		}
+ #ifdef BSD4_3
  		if (ifp)
  			m->m_off += sizeof(ifp);
+ #endif
  		/*
  		 * If we have at least NBPG bytes,
  		 * allocate a new page.  Swap the current buffer page
***************
*** 398,424 ****
--- 460,495 ----
  		 * for the interface pointer.
  		 */
  		if (len >= NBPG) {
+ #if defined(BSD4_3) || defined(sun)
  			MCLGET(m);
+ #else
+ 			MCLGET(m, 0);
+ #endif
  			if (m->m_len == CLBYTES) {
  				cp = mtod(m, char *);
  				m->m_off = (int)sc->sc_buf - (int)m;
  				sc->sc_buf = cp;
+ #ifdef BSD4_3
  				if (ifp) {
  					m->m_off += sizeof(ifp);
  					count = MIN(len,
  					    CLBYTES - sizeof(struct ifnet *));
  				} else
+ #endif
  					count = MIN(len, CLBYTES);
  				goto nocopy;
  			}
  		}
+ #ifdef BSD4_3
  		if (ifp)
  			count = MIN(len, MLEN - sizeof(ifp));
  		else
+ #endif
  			count = MIN(len, MLEN);
  		bcopy(cp, mtod(m, caddr_t), count);
  nocopy:
  		m->m_len = count;
+ #ifdef BSD4_3
  		if (ifp) {
  			m->m_off -= sizeof(ifp);
  			m->m_len += sizeof(ifp);
***************
*** 425,430 ****
--- 496,502 ----
  			*mtod(m, struct ifnet **) = ifp;
  			ifp = NULL;
  		}
+ #endif
  		cp += count;
  		len -= count;
  		mp = &m->m_next;
***************
*** 515,535 ****
--- 587,669 ----
  	int cmd;
  	caddr_t data;
  {
+ #ifdef BSD4_3
  	register struct ifaddr *ifa = (struct ifaddr *)data;
+ #else
+ #ifdef sun
+ 	register struct sockaddr *addr = (struct sockaddr *)data;
+ #else
+ 	register struct ifreq *ifr = (struct ifreq *)data;
+ 	register struct sockaddr *addr;
+ #endif
+ #endif
  	int s = splimp(), error = 0;
  
  	switch (cmd) {
  
  	case SIOCSIFADDR:
+ #ifdef BSD4_3
  		if (ifa->ifa_addr.sa_family == AF_INET)
  			ifp->if_flags |= IFF_UP;
+ #else
+ #ifndef sun
+ 		addr = &ifr->ifr_addr;
+ #endif
+ 		if (addr->sa_family == AF_INET) {
+ 			struct sockaddr oldaddr;
+ 			struct sockaddr_in netaddr;
+ 			int s = splimp();
+ 		
+ 			oldaddr = ifp->if_addr;
+ 			ifp->if_addr = *addr;
+ 		
+ 			/*
+ 			 * Delete any previous route for an old address.
+ 			 */
+ 			bzero((caddr_t)&netaddr, sizeof (netaddr));
+ 			netaddr.sin_family = AF_INET;
+ 			if (ifp->if_flags & IFF_ROUTE) {
+ 				rtinit(&ifp->if_dstaddr, &oldaddr, RTF_HOST);
+ 				ifp->if_flags &= ~IFF_ROUTE;
+ 			}
+ 			ifp->if_net = in_netof(((struct sockaddr_in *)(addr))->sin_addr);
+ 			splx(s);
+ 			/*
+ 			 * Add route for the network.
+ 			 */
+ 			if (ifp->if_flags & IFF_POINTOPOINT)
+ 				rtinit(&ifp->if_dstaddr, &ifp->if_addr,
+ 				    RTF_HOST|RTF_UP);
+ 			ifp->if_flags |= IFF_ROUTE | IFF_UP;
+ 		}
+ #endif
  		else
  			error = EAFNOSUPPORT;
  		break;
  
  	case SIOCSIFDSTADDR:
+ #ifdef BSD4_3
  		if (ifa->ifa_addr.sa_family != AF_INET)
+ #else
+ #ifndef sun
+ 		addr = &ifr->ifr_addr;
+ #endif
+ 		if (addr->sa_family != AF_INET)
+ #endif
  			error = EAFNOSUPPORT;
+ #ifndef BSD4_3
+ 		else {
+ 			struct sockaddr oldaddr;
+ 
+ 			oldaddr = ifp->if_dstaddr;
+ 			ifp->if_dstaddr = *addr;
+ 			if (ifp->if_flags & IFF_ROUTE) {
+ 				rtinit(&oldaddr, &ifp->if_addr, -1);
+ 				rtinit(&ifp->if_dstaddr, &ifp->if_addr,
+ 				    RTF_HOST|RTF_UP);
+ 			}
+ 		}
+ #endif
  		break;
  
  	default:
***************
*** 538,541 ****
--- 672,689 ----
  	splx(s);
  	return (error);
  }
+ 
+ #ifndef BSD4_3
+ locc(mask, size, cp)
+ 	register u_char mask;
+ 	u_int size;
+ 	register u_char *cp;
+ {
+ 	register u_char *end = &cp[size];
+ 
+ 	while (cp < end && *cp != mask)
+ 		cp++;
+ 	return (end - cp);
+ }
+ #endif
  #endif
